package cn.edu.scau.cmi.dengzejun.chapter10;

import java.io.*;

public class Example11 {
	public static void main(String args[]) {
		String command = "Marisa is my wife";
		EncryptAndDecrypt person = new EncryptAndDecrypt();
		String password = "Reimu";
		String secret = person.encrypt(command, password);
		File file = new File("secret.txt");
		try {
			FileOutputStream fos = new FileOutputStream(file);
			DataOutputStream outData = new DataOutputStream(fos);
			outData.writeUTF(secret);
			System.out.println("Encrypt the command :"+command);
		}catch(IOException e) {
			System.out.println(e);
		}
		try {
			FileInputStream fis = new FileInputStream(file);
			DataInputStream inData = new DataInputStream(fis);
			String str = inData.readUTF();
			String plaintext = person.decrypt(str, password);
			System.out.println("Decrypt the command is "+plaintext);
		}catch(IOException e) {
			System.out.println(e);
		}
		return;
	}
}
